<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
    $pageindex = max(1, intval($_GPC['page']));
    $pagesize=8;
    $type=isset($_GPC['type'])?$_GPC['type']:'all';
    $where=" where a.uniacid=:uniacid";
    $data[':uniacid']=$_W['uniacid']; 
    if($type=='now'){
    $where.=" and a.status=1";
    }

    if($type=='all'){
    
    }
    if($type=='ok'){
    $where.=" and a.status=2";
    }

    $sql="SELECT a.*,b.name FROM ".tablename('zhtc_ad_from'). " a"  . " left join " . tablename("zhtc_user") . " b on a.user_id=b.id  ".$where." ORDER BY a.id DESC";
    $total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zhtc_ad_from'). " a"  . " left join " . tablename("zhtc_user") . " b on a.user_id=b.id ".$where." ORDER BY a.id DESC",$data);
    $select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
    $pager = pagination($total, $pageindex, $pagesize);
    $list=pdo_fetchall($select_sql,$data);
    // echo "<pre>";
    // print_r($list);die();
    foreach ($list as $key => $value) {
        $list[$key]['create_time'] = date("Y-m-d H:i",$value['create_time']);
        $list[$key]['update_time'] = date("Y-m-d H:i",$value['update_time']);
    }
    if($_GPC['op']=='look'){
        //$sqls = "UPDATE ".tablename('zhtc_ad_from'). " SET status=2 WHERE id=".$_GPC['id'];
        //echo $sqls;die();
        $res=pdo_update('zhtc_ad_from',array('status'=>2,'update_time'=>time()),array('id'=>$_GPC['id']));
        if($res){
             message('已读！', $this->createWebUrl('form'), 'success');
            }else{
                  message($res,'','error');
            }
    }
    if($_GPC['op']=='delete'){
        $res=pdo_delete('zhtc_ad_from',array('id'=>$_GPC['id']));
        if($res){
             message('删除成功！', $this->createWebUrl('form'), 'success');
            }else{
                  message('删除失败！','','error');
            }
    }
// echo "<pre>";
// print_r($list);die;
include $this->template('web/form');